﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml.Linq;

namespace FinanceCalculators.Views.HomeAffordability
{
    public partial class HomeAffordability : PhoneApplicationPage
    {
        public HomeAffordability()
        {
            InitializeComponent();
        }
        private void LoadHOusingExpensIncomeRation()
        {
            List<HomeAffProperties> objheir = new List<HomeAffProperties>();
            XDocument xdoc = XDocument.Load("DispalyData/HousingexpenseIncomeRatio.xml");
            var elehir = from i in xdoc.Descendants("amount") select i;
            foreach (var element in elehir)
            {
                HomeAffProperties objhr = new HomeAffProperties();
                objhr.HOusingExpensepercentages = element.Value;
                objheir.Add(objhr);
            }
            lstpicHousingExpenseIncomeRatio.ItemsSource = objheir;

        }

        private void LoadLongTermDebtRatio()
        {
            List<HomeAffProperties> objtdr = new List<HomeAffProperties>();
            XDocument xdoc = XDocument.Load("DispalyData/LongTermDebtRatio.xml");
            var elelong = from i in xdoc.Descendants("amount") select i;
            foreach (var element in elelong)
            {
                HomeAffProperties objele = new HomeAffProperties();
                objele.LongTermDebtpercentages = element.Value;
                objtdr.Add(objele);
            }
            lstpicLongTermDebtIncomeRatio.ItemsSource = objtdr;
        }


        private void LoadPrivateMortageInsurance()
        {
            List<HomeAffProperties> objpmi = new List<HomeAffProperties>();
            XDocument xdoc = XDocument.Load("DispalyData/PrivateMortageInsurance.xml");
            var elepmi = from i in xdoc.Descendants("amount") select i;
            foreach (var element in elepmi)
            {
                HomeAffProperties objcl = new HomeAffProperties();
                objcl.PrivateMortageInsura = element.Value;
                objpmi.Add(objcl);
            }
            lstPicprivateMortageInsurance.ItemsSource = objpmi;
        }

        private void LoadHazardinsurancepercetages()
        {

            List<HomeAffProperties> objhard = new List<HomeAffProperties>();
            XDocument xdoc = XDocument.Load("DispalyData/HazardInsuranceRate.xml");
            var hazardele = from i in xdoc.Descendants("amount") select i;
            foreach (var element in hazardele)
            {
                HomeAffProperties objha = new HomeAffProperties();
                objha.HazardInsuranceRate = element.Value;
                objhard.Add(objha);
            }
            lstpicHazardInsuranceRate.ItemsSource = objhard;

        }

        private void LoadClosingCostPercentages()
        {
            List<HomeAffProperties> objclscost = new List<HomeAffProperties>();
            XDocument xdoc = XDocument.Load("DispalyData/closingcost.xml");
            var clsele = from i in xdoc.Descendants("amount") select i;
            foreach (var element in clsele)
            {
                HomeAffProperties objclo = new HomeAffProperties();
                objclo.clsCostPercentage = element.Value;
                objclscost.Add(objclo);


            }
            lstpikClosingCost.ItemsSource = objclscost;
        }


        private void LoadMortagagePercentages()
        {
            List<HomeAffProperties> objMorList = new List<HomeAffProperties>();
            XDocument xdoc = XDocument.Load("DispalyData/MortagageData.xml");
            var ele = from i in xdoc.Descendants("amount")
                      select i;
            foreach (var element in ele)
            {
                HomeAffProperties objMor = new HomeAffProperties();
                objMor.mtgPercentage = element.Value;
                objMorList.Add(objMor);
            }

            lstpicMortage.ItemsSource = objMorList;

        }

        //private void btncalculator_Click(object sender, RoutedEventArgs e)
        //{
        //    NavigationService.Navigate(new Uri("/Views/HomeAffordability/HomeAffResult.xaml", UriKind.Relative));
        //}

        //private void Btncalculator_Click_1(object sender, RoutedEventArgs e)
        //{
        //    NavigationService.Navigate(new Uri("/Views/HomeAffordability/HomeAffResult.xaml", UriKind.Relative));
        //}

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            LoadMortagagePercentages();
            LoadClosingCostPercentages();
            LoadHazardinsurancepercetages();
            LoadPrivateMortageInsurance();
            LoadLongTermDebtRatio();
            LoadHOusingExpensIncomeRation();
        }

        //private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        // {
        //     txtGrossIncome.Focus();
        //        if (ErrorReport)
        //            NavigationService.Navigate(new Uri("/Views/HomeAffordability/HomeAffResult.xaml?gi=" + txtGrossIncome.Text + "&md=" + txtMinMontlyDebtPayment.Text + "&fa=" + txtFundsAvailble.Text + "&lm=" + lstpicMortage.Text + "&cc=" + lstpikClosingCost.Text + "&ldp=" + listmindownpayment.Text + "&lptr=" + lstpicPropertyTaxRate.Text + "&lhir=" + lstpicHazardInsuranceRate.Text + "&cc=" + (lstPicprivateMortageInsurance.SelectedItem as CompareLoanByRate).Closincostsper, UriKind.Relative));
        //            //no need to give validation 4 list picker
        //        else
        //            MessageBox.Show("Please enter the values", "Request", MessageBoxButton.OKCancel);

        //}
        ////private bool errorreport;
        //public bool ErrorReport
        //{
        //    get
        //    {
        //        bool isTextBoxEmpty = false;
        //        if (txtGrossIncome.Text != "" && txtMinMontlyDebtPayment.Text != "" && txtFundsAvailble.Text != "")
        //            isTextBoxEmpty = true;
        //        return isTextBoxEmpty;
        //    }
        //}

        //}
    }
}
